package com.link2room.soundwave.controller.task;


import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.dto.param.base.BaseL2rParamDto;
import com.link2room.soundwave.dto.param.base.PmsRateParamDto;
import com.link2room.soundwave.dto.param.inside.PmsRoomAvailInsideParamDto;
import com.link2room.soundwave.dto.param.inside.ReservationStaInsideParamDto;
import com.link2room.soundwave.util.HandlerUtil;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

/**
 * Created by sss on 2016/6/27.
 */
@Api(tags = "定时任务")
@RestController
@RequestMapping("/Task")
public class PMSSyncTaskController {
    @RequestMapping("/syncPMSRoomAvail")
    public void avail(
            @RequestParam(value = "lhotelGroupCode", required = false) String hotelGroupCode,
            @RequestParam(value = "lhotelCode", required = false) String hotelCode,
            @RequestParam(value = "startIndex", required = false) Long startIndex,
            @RequestParam(value = "dayStep", required = false) Long dayStep
    ) throws Exception {
        PmsRoomAvailInsideParamDto pmsRoomAvailInsideParamDto = new PmsRoomAvailInsideParamDto();
        pmsRoomAvailInsideParamDto.setLhotelGroupCode(hotelGroupCode);
        pmsRoomAvailInsideParamDto.setLhotelCode(hotelCode);
        if (startIndex != null) {
            pmsRoomAvailInsideParamDto.setStartIndex(startIndex);
        }
        if (dayStep != null) {
            pmsRoomAvailInsideParamDto.setDayStep(dayStep);
        }
        HandlerUtil.pmsRoomAvailHandler().syncPMSRoomAvailHandler(pmsRoomAvailInsideParamDto);
    }


    @RequestMapping("/syncReservationSta")
    public String reservationSta(
            @RequestParam(value = "lhotelCode", required = false) String lhotelCode
    ) throws Exception {
        ReservationStaInsideParamDto reservationStaInsideParamDto = new ReservationStaInsideParamDto();
        reservationStaInsideParamDto.setLhotelCode(lhotelCode);
        HandlerUtil.pmsReservationHandler().syncReservationStaHandler(reservationStaInsideParamDto);
        return "";
    }

    @RequestMapping(value="/SyncPMSRates")
    public BaseResultDto syncPMSRates(
            @RequestParam(value = "lhotelCode", required = false) String lhotelCode,
            @RequestParam(value = "dayStep", required = false) Long dayStep,
            @RequestParam(value = "isOverride", required = false) String isOverride
    ) throws Exception{
        PmsRateParamDto baseL2rParamDto=new PmsRateParamDto();
        baseL2rParamDto.setLhotelCode(lhotelCode);
        baseL2rParamDto.setDayStep(dayStep);
        baseL2rParamDto.setIsOverride(isOverride);
        HandlerUtil.pmsRateHandler().syncPMSRateHandler(baseL2rParamDto);
        BaseResultDto baseResultDto = new BaseResultDto();
        baseResultDto.setResultCode(0);
        return  baseResultDto;
    }

    @RequestMapping(value="/SyncPMSRatesIncement")
    public BaseResultDto syncPMSRatesIncement(
            @RequestParam(value = "lhotelCode", required = false) String lhotelCode,
            @RequestParam(value = "dayStep", required = false) Long dayStep
    ) throws Exception{
        PmsRateParamDto baseL2rParamDto=new PmsRateParamDto();
        baseL2rParamDto.setLhotelCode(lhotelCode);
        baseL2rParamDto.setDayStep(dayStep);
        HandlerUtil.pmsRateHandler().syncPMSRateIncrementHandler(baseL2rParamDto);
        BaseResultDto baseResultDto = new BaseResultDto();
        baseResultDto.setResultCode(0);
        return  baseResultDto;
    }

    @RequestMapping("/deleteAvail")
    public BaseResultDto pricePools(
            @RequestParam(value = "dayStep" ,required = false) Long dayStep
    ) throws Exception {
        BaseL2rParamDto baseL2rParamDto =new BaseL2rParamDto();
        if(dayStep==null){
            dayStep=1L;
        }
        baseL2rParamDto.setDayStep(dayStep);
        HandlerUtil.pmsRoomAvailHandler().deletePmsRoomAvailHandler(baseL2rParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        return l2rRs;
    }
}
